package com.wgts.wgts.mvp.view.activity.shopkeeper;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.wgts.wgts.R;
import com.wgts.wgts.control.recycleview.BaseLoadMoreAdapter;
import com.wgts.wgts.netmodle.resp.OperatingDataEntity;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class OperatingDataAdapter extends BaseLoadMoreAdapter<OperatingDataAdapter.OperatingDataViewHolder> {



    private Context context;

    private List<OperatingDataEntity.Entity> srcDate;

    public OperatingDataAdapter(Context context, List<OperatingDataEntity.Entity> srcDate) {
        super(context);
        this.context = context;
        this.srcDate = srcDate;
    }

    @NonNull
    @Override
    public OperatingDataViewHolder onCreateBodyViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new OperatingDataViewHolder(LayoutInflater.from(context).inflate(R.layout.operating_data_view_holder, viewGroup, false));
    }

    @Override
    public void onBindBodyViewHolder(@NonNull OperatingDataViewHolder operatingDataViewHolder, int i) {
        operatingDataViewHolder.tvOrderNumber.setText("订单号" + srcDate.get(i).orderCode);
        switch (srcDate.get(i).orderState){
            case  "UNPAID":
                operatingDataViewHolder.tvOrderState.setText("待支付");
                break;
            case "UNDELIVER":
                operatingDataViewHolder.tvOrderState.setText("待发货");
                break;
            case "UNRECEIPT":
                operatingDataViewHolder.tvOrderState.setText("待收货");
                break;
            case "UNEVALUATED":
                operatingDataViewHolder.tvOrderState.setText("待评价");
                break;
            case "COMPLETED":
                operatingDataViewHolder.tvOrderState.setText("已完成");
                break;
            case "RETURN_GOOD":
                operatingDataViewHolder.tvOrderState.setText("退货单");
                break;
        }

        operatingDataViewHolder.tvGoodsNumber.setText("共" + srcDate.get(i).products.size() +"件，实付款：");

        operatingDataViewHolder.tvMoney.setText(srcDate.get(i).orderTruePrice + "元");



        operatingDataViewHolder.tvGetMoney.setText(Html.fromHtml(String.format(context.getResources().getString(R.string.string_get_money), "￥" + srcDate.get(i).commissionProfit)));

        operatingDataViewHolder.tvTime.setText(srcDate.get(i).createDate + srcDate.get(i).createTime);

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        operatingDataViewHolder.goodRecyView.setLayoutManager(linearLayoutManager);
        operatingDataViewHolder.goodRecyView.setAdapter(new OperatingProductAdapter(srcDate.get(i).products, context));
    }

    @Override
    public int getBodyItemCount() {
        return srcDate.size();
    }

    @Override
    public int getBodyItemViewType(int position) {
        return 0;
    }


    public class OperatingDataViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_order_number)
        TextView tvOrderNumber;
        @BindView(R.id.tv_order_state)
        TextView tvOrderState;
        @BindView(R.id.good_recy_view)
        RecyclerView goodRecyView;
        @BindView(R.id.tv_goods_number)
        TextView tvGoodsNumber;
        @BindView(R.id.tv_money)
        TextView tvMoney;
        @BindView(R.id.tv_get_money)
        TextView tvGetMoney;
        @BindView(R.id.tv_time)
        TextView tvTime;

        public OperatingDataViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
